package com.gs.m_home.observal

import com.gs.common.observer.ValueObserver

class ValueObserval<T : Any> {
    private val observers: ArrayList<ValueObserver<T>> = ArrayList()

    fun addObserver(observer: ValueObserver<T>) {
        this.observers.add(observer)
    }

    fun removeLastObserver() {
        val size = this.observers.size
        if (size > 0) {
            this.observers.removeAt(size - 1)
        }
    }

    fun removeAllObservers() {
        if (this.observers.size > 0) {
            this.observers.clear()
        }
    }

    fun notifyObserver(value: T) {
        for (observer in observers) {
            observer.update(value)
        }
    }

    fun notifyObserver(condition: String, value: T) {
        for (observer in observers) {
            observer.update(condition, value)
        }
    }
}